package com.xiaoxu.maxTemp;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int maxValue = Integer.MIN_VALUE;
        // key = 1995  values = [5,2]
        //key = 1994  values = [2,-8]
        for (IntWritable value : values) {
            maxValue = Math.max(maxValue, value.get());
        }
        /**
         * key 1995 maxValue=5
         * key 1994 maxValue=2
         */
        context.write(key, new IntWritable(maxValue));
    }
}
